package com.kehongborui.fliggy.controller;

import com.kehongborui.fliggy.model.QueryVehicleModel;
import com.kehongborui.fliggy.model.VehicleModel;
import com.kehongborui.fliggy.service.VehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author zhang peng yang ming
 * @CopyRight (C) http://www.csdn.com
 * @brief
 * @email 122162005@qq.com
 * @date 2018-08-27
 */
@Controller
@RequestMapping("/search")
public class SearchController {
    @Autowired
    private VehicleService vehicleService;

    @GetMapping("/{type}") // vehicle/
    public String search(@PathVariable("type") String type, QueryVehicleModel model, ModelMap map) {
        String dep = model.getDepStation();
        String arr = model.getArrStation();
        if ("vehicle".equals(type)) {
//            List<VehicleModel> vehicleModels = vehicleService.findByDepArrStationAndDate(model);
//
//            map.addAttribute("vehicleModels", vehicleModels);
//            map.addAttribute("dep", dep);
//            map.addAttribute("arr", arr);
//            map.addAttribute("type", type);

        } else if ("train".equals(type)) {
            List<VehicleModel> vehicleModels = vehicleService.findByDepArrStationAndDate(model);

            map.addAttribute("vehicleModels", vehicleModels);
            map.addAttribute("dep", dep);
            map.addAttribute("arr", arr);
            map.addAttribute("type", type);

        }
        return "searchResult";

//        return "redirect:/";
    }
}
